/*
* wis.h  (c) 2013 wiimu.com liaods <dongsheng.liao@gmail.com>
*/
                                                             
#ifndef __WIS_H__
#define __WIS_H__

#define MSG_LEVEL_NONE  0
#define MSG_LEVEL_ERROR 1
#define MSG_LEVEL_DEBUG 2

#define MAX_WIS_DATA_LEN 1048576//1024

// 0x8000 - 0x8100 is reserved for wis_server
typedef enum  
{
    WIS_CMD_UNKNOWN = -1,
/* commands for wis_client(device) */
    
    WIS_CMD_CGI_URL  = 0x7000,
    
    WIS_CMD_HEART_BEAT = 0x8000,
    WIS_CMD_LOGIN,
    WIS_CMD_POWEROFF,
    WIS_CMD_REBOOT,
    WIS_CMD_WEBSIGNAL,
    WIS_CMD_RESULT,
    WIS_CMD_TO_USER,
    WIS_CMD_RESULT2,
/* commands for pc client(Android/iOS/PC/...) */
    WIS_CMD_USER_HEART_BEAT = 0x8080, 
    WIS_CMD_USER_PRIVATE,
    WIS_CMD_USER_LOGIN,    
    WIS_CMD_USER_BIND,
    WIS_CMD_USER_UNBIND,
    WIS_CMD_USER_GET_DEVICES,
    WIS_CMD_USER_GET_DEVICE_INFO,
    WIS_CMD_USER_GET_DEVICE_STATUS,
}WisCmdID;

typedef struct {
	char uuid[32];
    char name[32];
	char bind_time[20];
	int status;  /* bit 0 ( 1 online, 0 offline ) */
} wis_user_dev;

typedef struct {
	int num;
	wis_user_dev devs[0];
} wis_user_dev_list;

typedef struct {
	char uuid[32];
	int status;
} wis_user_dev_status;

typedef struct {
	char uuid[32];
//	char user_data[256];
	char license[32];
	char version[32];
	char reg_time[20];
	char login_time[20];
	int login_cnt;
	int status;
} wis_user_dev_info;

typedef struct {
	char uuid[32];
	int  cmd;
	int  arg_len;
	char arg[0];
} wis_user_private_cmd;

typedef struct 
{
    unsigned int checksum;
    unsigned int cmdId;
    unsigned int cmdDataLength;
    unsigned char cmdData[];
} WisSocketCmd;

typedef enum 
{
    WIS_SOCKET_FAILED = -1,
    WIS_SOCKET_SUCCESS = 0,
} WisSocketStatus;

enum {
    WIS_CMD_TX_LED_ON = 0x8200,
    WIS_CMD_TX_LED_OFF,
    WIS_CMD_RX_LED_ON,
    WIS_CMD_RX_LED_OFF,
};

//Add by anson 14-03
enum {
    WIS_CMD_V2_SYS_INFO_GET = 0x1000,
    WIS_CMD_V2_DEV_LIST_GET = 0x2000,
    WIS_CMD_V2_DEV_SWITCH_SET = 0x2001,
    WIS_CMD_V2_DOORLOOK_SET = 0x2002,
    WIS_CMD_V2_METER_VAL_SET = 0x2003,
    WIS_CMD_V2_THERMOSTAT_SET = 0x2004,
    WIS_CMD_V2_THERMOSTAT_GET = 0x2005,
    WIS_CMD_V2_DEV_STAT_CHANGE_GET = 0x2006,
   
    WIS_CMD_V2_CMD_CAM_LIST_GET = 0x3000,
    WIS_CMD_V2_CMD_CAM_CTRL = 0x3001,
};

typedef struct
{
    char uuid[32];
    char did[8];
    int value;
} WisDevSwitchSetCmd;

typedef struct
{
    char uuid[32];
    char did[8];
    int  set_index;    // ndex==set_index
    int value;
    int unit;          // 0-C, 1-F
} WisDevThermostatSetCmd;

typedef struct
{
    char uuid[32];
    char did[8];
    int  get_index;  // get_index
} WisDevThermostatGetCmd;

typedef struct {
	char session_id[32];
	char data[0];
} wis_result;

typedef struct
{
	int 	cmd;		// 命令	（4 bytes)
	int 	stat;		// 命令的执行状态	0 - 成功， -1 - 失败（4 bytes)
	int 	data_len;	// 返回数据的长度（4 bytes)
	char 	data[0];	// 返回数据
}UserCmdRet_t;

// 系统信息格式
typedef struct
{
	char 	name[32];			// 名称( ZWave-Demo)
	char   	hw_ver[8];			//	硬件版本
	char	sw_ver[8];			// 	软件版本
	char	mac_addr[20];		// MAC地址
	char 	local_ip_addr[20];	// 内网IP地址
	char 	public_ip_addr[20]; // 公网IP
	char 	http_port[8];		// WEB监听端口
}SysInfo_t;

#pragma mark - CGI Request
typedef struct
{
    char uuid[32];
    char msg_id;
    char url[30];       //'\0' 包含结束
}cgi_request_t;


typedef struct
{
    char msg_id;    //请求时发送的msg_id
    char data[0];   //数据跟内网访问cgi的数据一致。
}cgi_response_t;

#endif


